package GUI;

import 数据库和网络.myDatebase;
import 试题和试卷.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;

public class questionAddWindow extends JFrame {
    public static void main(String[] args) {
        new questionAddWindow(1);
    }
    public static JPanel mainPanel;
    static int currentPage;
    static int page;
    static int size;
    static ArrayList<questionAddItem> defList;
    static ArrayList<questionAddItem> selList;
    static ArrayList<question> sel;
    static ArrayList<questionAddItem> fillList;
    static ArrayList<questionAddItem> subList;
    static ArrayList<question> def;

    static ArrayList<question> fill;
    static ArrayList<question> sub;

    JLabel num;
    JLabel paperLabel;
    static JLabel pageNumberLabel;
    static JLabel infoLabel;

    static JButton nextButton,preButton,addButton,backButton;
    static Font font = new Font("sanserif",Font.BOLD,10);
    Font pageNumberFont = new Font("sanserif",Font.BOLD,12);
    double min=organizePaperWindow.randomOrganize.min;
    double max=organizePaperWindow.randomOrganize.max;

    public questionAddWindow(int type){

        displayFrame();
        if(type==1){
            addSelection();
        }
        if(type==2){
            addDefinition();
        }
        if(type==3){
            addFillingBlank();
        }
        if(type==4){
            addSubjective();
        }
        if(type==5){
            addRandomSelection();
        }
        if(type==6){
            addRandomDefinition();
        }
        if(type==7){
            addRandomFillingBlank();
        }
        if(type==8){
            addRandomSubjective();
        }


    }
    public  void setTitleType(JLabel label) {
        Font bigFont = new Font("sanserif", Font.PLAIN, 16);
        label.setBackground(Color.lightGray);
        label.setOpaque(true);
        label.setFont(bigFont);
        label.setBorder(BorderFactory.createLineBorder(Color.darkGray));
        label.setHorizontalAlignment(SwingConstants.CENTER);
    }

    public void setTextType(JLabel label) {
        Font smallFont = new Font("sanserif", Font.PLAIN, 12);
        label.setBackground(Color.white);
        label.setOpaque(true);
        label.setFont(smallFont);
        label.setBorder(BorderFactory.createLineBorder(Color.lightGray));
        label.setHorizontalAlignment(SwingConstants.CENTER);
    }

    public void setButtonType(JButton button) {
        Font smallFont = new Font("sanserif", Font.PLAIN, 14);
        button.setBackground(Color.GRAY);
        button.setFont(smallFont);
        button.setBorder(BorderFactory.createLineBorder(Color.darkGray));
        button.setHorizontalAlignment(SwingConstants.CENTER);
    }
    public void addSelection(){

        currentPage=1;
        myDatebase selQuery=new myDatebase("questioncollection");
        sel= new ArrayList<>();
        selList= new ArrayList<>();
        String sql="select * from questioncollection.selection_question";
        try {
            selQuery.statement.execute(sql);
            selQuery.resultSet=selQuery.statement.executeQuery(sql);

            while(selQuery.resultSet.next()){
                String title=selQuery.resultSet.getString(2);
                String text=selQuery.resultSet.getString(3);
                Double dif=selQuery.resultSet.getDouble(4);
                int full=selQuery.resultSet.getInt(5);
                String a=selQuery.resultSet.getString(6);
                String b=selQuery.resultSet.getString(7);
                String c=selQuery.resultSet.getString(8);
                String d=selQuery.resultSet.getString(9);
                String answer= selQuery.resultSet.getString(10);
                question curr=new selectionQuestion(title,text,"selection",dif,full,answer);
                curr.setOption_a(a);
                curr.setOption_b(b);
                curr.setOption_c(c);
                curr.setOption_d(d);

                sel.add(curr);

            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        Iterator<question> ite=sel.iterator();
        int t=0;
        while(ite.hasNext()){
            question i=ite.next();
            ++t;
            selList.add(new selectionAddItem(t,i));

            //add(selList.get(t-1));
            mainPanel.updateUI();
        }


        size = sel.size();
        page=size/5+1;




        displayFrame();


        for (int i=0;i<sel.size();i++) {
            for (int j = 0; j < organizePaperWindow.selectionQuestions.size(); j++) {
                if (sel.get(i).getTitle().equals(organizePaperWindow.selectionQuestions.get(j).getTitle())) {
                    selList.get(i).detailButton.setEnabled(false);
                    selList.get(i).deleteButton.setEnabled(true);
                    mainPanel.updateUI();
                }
            }
        }

        if (page == 1) {
            for (int i = 1; i <= size; i++) {
                add(selList.get(i-1));//i---->i-1
            }
        } else if (page > 1) {
            for (int i = (currentPage - 1) * 5; i <= currentPage * 5 - 1; i++) {
                add(selList.get(i));
            }

        }





        mainPanel.updateUI();
        addButton.addActionListener(new finishListener());
        infoLabel.setText("选择题题目数目："+sel.size());
        nextButton.removeAll();
        preButton.removeAll();
        nextButton.addActionListener(new selNextListener());
        preButton.addActionListener(new selPreListener());

    }
    public void addDefinition(){
        currentPage = 1;
        myDatebase selQuery = new myDatebase("questioncollection");
        def = new ArrayList<>();
        defList = new ArrayList<>();
        String sql = "select * from questioncollection.definition_question";
        try {
            selQuery.statement.execute(sql);
            selQuery.resultSet = selQuery.statement.executeQuery(sql);
            while (selQuery.resultSet.next()) {
                String title = selQuery.resultSet.getString(2);
                String text = selQuery.resultSet.getString(3);
                Double dif = selQuery.resultSet.getDouble(4);
                int full = selQuery.resultSet.getInt(5);
                String right = selQuery.resultSet.getString(6);
                String wrong = selQuery.resultSet.getString(7);
                String answer = selQuery.resultSet.getString(8);
                question curr = new definitionQuestion(title, text, "selection", dif, full, answer);
                curr.setRightOption(right);
                curr.setWrongOption(wrong);

                def.add(curr);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        Iterator<question> ite = def.iterator();
        int t = 0;
        while (ite.hasNext()) {
            question i = ite.next();
            ++t;
            defList.add(new definitionAddItem(t, i));
            //add(defList.get(t - 1));
            //mainPanel.updateUI();
        }
        size = def.size();
        page=size/5+1;
        displayFrame();

        for (int i=0;i<def.size();i++) {
            for (int j = 0; j < organizePaperWindow.definitionQuestions.size(); j++) {
                if (def.get(i).getTitle().equals(organizePaperWindow.definitionQuestions.get(j).getTitle())) {
                    defList.get(i).detailButton.setEnabled(false);
                    defList.get(i).deleteButton.setEnabled(true);
                    mainPanel.updateUI();
                }
            }
        }


        if (page == 1) {
            for (int i = 0; i <size; i++) {
                add(defList.get(i));
            }
        } else if (page > 1) {
            for (int i = (currentPage - 1) * 5; i <= currentPage * 5 - 1; i++) {
                add(defList.get(i));
            }
        }

        addButton.addActionListener(new finishListener());
        nextButton.addActionListener(new defNextListener());
        preButton.addActionListener(new defPreListener());
        infoLabel.setText("判断题题目数目：" + def.size());
        mainPanel.updateUI();



    }
    public void addFillingBlank(){
        mainPanel.removeAll();
        currentPage=1;
        fill= new ArrayList<>();
        fillList= new ArrayList<>();
        myDatebase selQuery=new myDatebase("questioncollection");
        String sql="select * from questioncollection.fillingblank_question";
        try {
            selQuery.statement.execute(sql);
            selQuery.resultSet=selQuery.statement.executeQuery(sql);
            while(selQuery.resultSet.next()){
                String title=selQuery.resultSet.getString(2);
                String text=selQuery.resultSet.getString(3);
                Double dif=selQuery.resultSet.getDouble(4);
                int full=selQuery.resultSet.getInt(5);
                String answer=selQuery.resultSet.getString(6);
                question curr=new fillingblankQuestion(title,text,"selection",dif,full,answer);
                fill.add(curr);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        Iterator<question> ite=fill.iterator();
        int t=0;
        while(ite.hasNext()){
            question i=ite.next();
            ++t;
            fillList.add(new fillingBlankAddItem(t,i));
        }
        size = fill.size();
        page=size/5+1;
        displayFrame();

        for (int i=0;i<fill.size();i++) {
            for (int j = 0; j < organizePaperWindow.fillingblankQuestions.size(); j++) {
                if (fill.get(i).getTitle().equals(organizePaperWindow.fillingblankQuestions.get(j).getTitle())) {
                    fillList.get(i).detailButton.setEnabled(false);
                    fillList.get(i).deleteButton.setEnabled(true);
                    mainPanel.updateUI();
                }
            }
        }

        if (page == 1) {
            for (int i = 0; i <size; i++) {
                add(fillList.get(i));
            }
        } else if (page > 1) {
            for (int i = (currentPage - 1) * 5; i <= currentPage * 5 - 1; i++) {
                add(fillList.get(i));
            }

        }

        mainPanel.updateUI();



        infoLabel.setText("填空题题目数目："+fill.size());
        mainPanel.updateUI();
        addButton.addActionListener(new finishListener());
        nextButton.removeAll();
        preButton.removeAll();
        nextButton.addActionListener(new fillNextListener());
        preButton.addActionListener(new fillPreListener());

    }
    public void addSubjective(){

        mainPanel.removeAll();
        currentPage=1;
        sub= new ArrayList<>();
        subList= new ArrayList<>();
        myDatebase selQuery=new myDatebase("questioncollection");
        String sql="select * from questioncollection.subjective_question";
        try {
            selQuery.statement.execute(sql);
            selQuery.resultSet=selQuery.statement.executeQuery(sql);
            while(selQuery.resultSet.next()){
                String title=selQuery.resultSet.getString(2);
                String text=selQuery.resultSet.getString(3);
                Double dif=selQuery.resultSet.getDouble(4);
                int full=selQuery.resultSet.getInt(5);
                String answer=selQuery.resultSet.getString(6);
                question curr=new subjectiveQuestion(title,text,"subjective",dif,full,answer);
                sub.add(curr);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        Iterator<question> ite=sub.iterator();
        int t=0;
        while(ite.hasNext()){
            question i=ite.next();
            t++;
            subList.add(new subjectiveAddItem(t,i));
        }
        size = sub.size();
        page=size/5+1;
        displayFrame();

        for (int i=0;i<sub.size();i++) {
            for (int j = 0; j < organizePaperWindow.subjectiveQuestions.size(); j++) {
                if (sub.get(i).getTitle().equals(organizePaperWindow.subjectiveQuestions.get(j).getTitle())) {
                    subList.get(i).detailButton.setEnabled(false);
                    subList.get(i).deleteButton.setEnabled(true);
                    mainPanel.updateUI();
                }
            }
        }

        if (page == 1) {
            for (int i = 0; i < size; i++) {
                add(subList.get(i));
            }
        } else if (page > 1) {
            for (int i = (currentPage - 1) * 5; i <= currentPage * 5 - 1; i++) {
                add(subList.get(i));
            }

        }

        mainPanel.updateUI();
        addButton.addActionListener(new finishListener());
        infoLabel.setText("简答题题目数目："+sub.size());
        mainPanel.updateUI();
        nextButton.removeAll();
        preButton.removeAll();
        nextButton.addActionListener(new subNextListener());
        preButton.addActionListener(new subPreListener());
    }
    public void addRandomSelection(){

        currentPage=1;
        myDatebase selQuery=new myDatebase("questioncollection");
        sel= new ArrayList<>();
        selList= new ArrayList<>();

        String sql="select * from questioncollection.selection_question where questionDifficulties between "+min+" and "+max+"";
        try {
            selQuery.statement.execute(sql);

            selQuery.resultSet=selQuery.statement.executeQuery(sql);

            while(selQuery.resultSet.next()){
                String title=selQuery.resultSet.getString(2);
                String text=selQuery.resultSet.getString(3);
                Double dif=selQuery.resultSet.getDouble(4);
                int full=selQuery.resultSet.getInt(5);
                String a=selQuery.resultSet.getString(6);
                String b=selQuery.resultSet.getString(7);
                String c=selQuery.resultSet.getString(8);
                String d=selQuery.resultSet.getString(9);
                String answer= selQuery.resultSet.getString(10);
                question curr=new selectionQuestion(title,text,"selection",dif,full,answer);
                curr.setOption_a(a);
                curr.setOption_b(b);
                curr.setOption_c(c);
                curr.setOption_d(d);

                sel.add(curr);

            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        Iterator<question> ite=sel.iterator();
        int t=0;
        while(ite.hasNext()){
            question i=ite.next();
            ++t;
            selList.add(new selectionAddItem(t,i));
            //add(selList.get(t-1));
            mainPanel.updateUI();
        }


        size = sel.size();
        page=size/5+1;




        displayFrame();
        if (page == 1) {
            for (int i = 1; i <= size; i++) {
                add(selList.get(i-1));//i---->i-1
            }
        } else if (page > 1) {
            for (int i = (currentPage - 1) * 5; i <= currentPage * 5 - 1; i++) {
                add(selList.get(i));
            }

        }
        mainPanel.updateUI();

        infoLabel.setText("选择题题目数目："+sel.size());
        nextButton.removeAll();
        preButton.removeAll();
        addButton.removeAll();
        addButton.addActionListener(new randomFinishListener());
        nextButton.addActionListener(new selNextListener());
        preButton.addActionListener(new selPreListener());

    }
    public void addRandomDefinition(){
        currentPage = 1;
        myDatebase selQuery = new myDatebase("questioncollection");
        def = new ArrayList<>();
        defList = new ArrayList<>();
        String sql = "select * from questioncollection.definition_question where questionDifficulties between "+min+" and "+max+"";
        try {
            selQuery.statement.execute(sql);
            selQuery.resultSet = selQuery.statement.executeQuery(sql);
            while (selQuery.resultSet.next()) {
                String title = selQuery.resultSet.getString(2);
                String text = selQuery.resultSet.getString(3);
                Double dif = selQuery.resultSet.getDouble(4);
                int full = selQuery.resultSet.getInt(5);
                String right = selQuery.resultSet.getString(6);
                String wrong = selQuery.resultSet.getString(7);
                String answer = selQuery.resultSet.getString(8);
                question curr = new definitionQuestion(title, text, "selection", dif, full, answer);
                curr.setRightOption(right);
                curr.setWrongOption(wrong);

                def.add(curr);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        Iterator<question> ite = def.iterator();
        int t = 0;
        while (ite.hasNext()) {
            question i = ite.next();
            ++t;
            defList.add(new definitionAddItem(t, i));
            //add(defList.get(t - 1));
            //mainPanel.updateUI();
        }
        size = def.size();
        page=size/5+1;
        displayFrame();

        if (page == 1) {
            for (int i = 0; i <size; i++) {
                add(defList.get(i));
            }
        } else if (page > 1) {
            for (int i = (currentPage - 1) * 5; i <= currentPage * 5 - 1; i++) {
                add(defList.get(i));
            }
        }


        nextButton.addActionListener(new defNextListener());
        preButton.addActionListener(new defPreListener());
        addButton.removeAll();
        addButton.addActionListener(new randomFinishListener());
        infoLabel.setText("判断题题目数目：" + def.size());
        mainPanel.updateUI();



    }
    public void addRandomFillingBlank(){
        mainPanel.removeAll();
        currentPage=1;
        fill= new ArrayList<>();
        fillList= new ArrayList<>();
        myDatebase selQuery=new myDatebase("questioncollection");
        String sql="select * from questioncollection.fillingblank_question where questionDifficulties between "+min+" and "+max+"";
        try {
            selQuery.statement.execute(sql);
            selQuery.resultSet=selQuery.statement.executeQuery(sql);
            while(selQuery.resultSet.next()){
                String title=selQuery.resultSet.getString(2);
                String text=selQuery.resultSet.getString(3);
                Double dif=selQuery.resultSet.getDouble(4);
                int full=selQuery.resultSet.getInt(5);
                String answer=selQuery.resultSet.getString(6);
                question curr=new fillingblankQuestion(title,text,"selection",dif,full,answer);
                fill.add(curr);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        Iterator<question> ite=fill.iterator();
        int t=0;
        while(ite.hasNext()){
            question i=ite.next();
            ++t;
            fillList.add(new fillingBlankAddItem(t,i));
        }
        size = fill.size();
        page=size/5+1;
        displayFrame();
        if (page == 1) {
            for (int i = 0; i <size; i++) {
                add(fillList.get(i));
            }
        } else if (page > 1) {
            for (int i = (currentPage - 1) * 5; i <= currentPage * 5 - 1; i++) {
                add(fillList.get(i));
            }

        }

        mainPanel.updateUI();



        infoLabel.setText("填空题题目数目："+fill.size());
        mainPanel.updateUI();

        nextButton.removeAll();
        preButton.removeAll();
        addButton.removeAll();
        addButton.addActionListener(new randomFinishListener());
        nextButton.addActionListener(new fillNextListener());
        preButton.addActionListener(new fillPreListener());

    }
    public void addRandomSubjective(){

        mainPanel.removeAll();
        currentPage=1;
        sub= new ArrayList<>();
        subList= new ArrayList<>();
        myDatebase selQuery=new myDatebase("questioncollection");
        String sql="select * from questioncollection.subjective_question where questionDifficulties between "+min+" and "+max+"";
        try {
            selQuery.statement.execute(sql);
            selQuery.resultSet=selQuery.statement.executeQuery(sql);
            while(selQuery.resultSet.next()){
                String title=selQuery.resultSet.getString(2);
                String text=selQuery.resultSet.getString(3);
                Double dif=selQuery.resultSet.getDouble(4);
                int full=selQuery.resultSet.getInt(5);
                String answer=selQuery.resultSet.getString(6);
                question curr=new subjectiveQuestion(title,text,"subjective",dif,full,answer);
                sub.add(curr);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        Iterator<question> ite=sub.iterator();
        int t=0;
        while(ite.hasNext()){
            question i=ite.next();
            t++;
            subList.add(new subjectiveAddItem(t,i));
        }
        size = sub.size();
        page=size/5+1;
        displayFrame();
        if (page == 1) {
            for (int i = 0; i < size; i++) {
                add(subList.get(i));
            }
        } else if (page > 1) {
            for (int i = (currentPage - 1) * 5; i <= currentPage * 5 - 1; i++) {
                add(subList.get(i));
            }

        }

        mainPanel.updateUI();

        infoLabel.setText("简答题题目数目："+sub.size());
        mainPanel.updateUI();
        nextButton.removeAll();
        preButton.removeAll();
        addButton.removeAll();
        addButton.addActionListener(new randomFinishListener());
        nextButton.addActionListener(new subNextListener());
        preButton.addActionListener(new subPreListener());
    }

    public  void add(questionAddItem item) {
        mainPanel.add(item.num);
        mainPanel.add(item.paperLabel);

        mainPanel.add(item.detailButton);
        mainPanel.add(item.deleteButton);

    }
    public  void remove(questionAddItem item) {
        mainPanel.remove(item.num);
        mainPanel.remove(item.paperLabel);

        mainPanel.remove(item.detailButton);
        mainPanel.remove(item.deleteButton);
    }

public class selNextListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {

        for(int i= (currentPage-1)*5;i<=currentPage*5-1;i++){
            remove(selList.get(i));
        }
        currentPage++;
        pageNumberLabel.setText(currentPage+"/"+page);
        if(currentPage!=1){
            mainPanel.add(preButton);}
        if(currentPage==page){
            mainPanel.remove(nextButton);
            for(int i= (currentPage-1)*5;i<size;i++){
                add(selList.get(i));
            }
        }else{
            for(int i= (currentPage-1)*5;i<=(currentPage*5-1);i++){
                add(selList.get(i));
            }
        }

        mainPanel.updateUI();

    }
}
public class selPreListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        for(int i=0;i<size;i++){
            remove(selList.get(i));
        }


        currentPage--;
        if(currentPage==1){
            mainPanel.remove(preButton);
        }
        pageNumberLabel.setText(currentPage+"/"+page);
        if(currentPage!=page){
            mainPanel.add(nextButton);
        }
        for(int i= (currentPage-1)*5;i<=currentPage*5;i++){
            add(selList.get(i));
        }

        if(currentPage<1){
            currentPage=1;
        }
        mainPanel.updateUI();
    }
}
public class defNextListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {

        for(int i= (currentPage-1)*5;i<=currentPage*5-1;i++){
            remove(defList.get(i));
        }
        currentPage++;
        pageNumberLabel.setText(currentPage+"/"+page);
        if(currentPage!=1){
            mainPanel.add(preButton);}
        if(currentPage==page){
            mainPanel.remove(nextButton);
            for(int i= (currentPage-1)*5;i<size;i++){
                add(defList.get(i));
            }
        }else{
            for(int i= (currentPage-1)*5;i<=(currentPage*5-1);i++){
                add(defList.get(i));
            }
        }

        mainPanel.updateUI();

    }
}
public class defPreListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        for(int i=0;i<size;i++){
            remove(defList.get(i));
        }


        currentPage--;
        if(currentPage==1){
            mainPanel.remove(preButton);
        }
        pageNumberLabel.setText(currentPage+"/"+page);
        if(currentPage!=page){
            mainPanel.add(nextButton);
        }
        for(int i= (currentPage-1)*5;i<=currentPage*5;i++){
            add(defList.get(i));
        }

        if(currentPage<1){
            currentPage=1;
        }
        mainPanel.updateUI();
    }
}
public class fillNextListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {

        for(int i= (currentPage-1)*5;i<=currentPage*5-1;i++){
            remove(fillList.get(i));
        }
        currentPage++;
        pageNumberLabel.setText(currentPage+"/"+page);
        if(currentPage!=1){
            mainPanel.add(preButton);}
        if(currentPage==page){
            mainPanel.remove(nextButton);
            for(int i= (currentPage-1)*5;i<size;i++){
                add(fillList.get(i));
            }
        }else{
            for(int i= (currentPage-1)*5;i<=(currentPage*5-1);i++){
                add(fillList.get(i));
            }
        }

        mainPanel.updateUI();

    }
}
public class fillPreListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        for(int i=0;i<size;i++){
            remove(fillList.get(i));
        }


        currentPage--;
        if(currentPage==1){
            mainPanel.remove(preButton);
        }
        pageNumberLabel.setText(currentPage+"/"+page);
        if(currentPage!=page){
            mainPanel.add(nextButton);
        }
        for(int i= (currentPage-1)*5;i<=currentPage*5;i++){
            add(fillList.get(i));
        }

        if(currentPage<1){
            currentPage=1;
        }
        mainPanel.updateUI();
    }
}
public class subNextListener implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {

        for(int i= (currentPage-1)*5;i<=currentPage*5-1;i++){
            remove(subList.get(i));
        }
        currentPage++;
        pageNumberLabel.setText(currentPage+"/"+page);
        if(currentPage!=1){
            mainPanel.add(preButton);}
        if(currentPage==page){
            mainPanel.remove(nextButton);
            for(int i= (currentPage-1)*5;i<size;i++){
                add(subList.get(i));
            }
        }else{
            for(int i= (currentPage-1)*5;i<=(currentPage*5-1);i++){
                add(subList.get(i));
            }
        }

        mainPanel.updateUI();

    }
}
public class subPreListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        for(int i=0;i<size;i++){
            remove(subList.get(i));
        }


        currentPage--;
        if(currentPage==1){
            mainPanel.remove(preButton);
        }
        pageNumberLabel.setText(currentPage+"/"+page);
        if(currentPage!=page){
            mainPanel.add(nextButton);
        }
        for(int i= (currentPage-1)*5;i<=currentPage*5;i++){
            add(subList.get(i));
        }

        if(currentPage<1){
            currentPage=1;
        }
        mainPanel.updateUI();
    }
}
    public void displayFrame() {
        mainPanel = new JPanel();
        Font bigFont = new Font("sanserif",Font.BOLD,24);
        mainPanel.setLayout(null);
        this.setTitle("试题库与组卷");
        this.setContentPane(mainPanel);
        this.setSize(980,700);
        mainPanel.setSize(this.getSize());
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        //this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        infoLabel = new JLabel("题目数目:");
        JLabel numLabel = new JLabel("序号");
        JLabel paperInfoLabel = new JLabel("题目信息");
        JLabel paperDetailLabel = new JLabel("添加");
        JLabel paperDeleteLabel = new JLabel("删除");


        preButton = new JButton("上一页");

        preButton.setBounds(740, 510, 70, 30);
        preButton.setFont(font);
        preButton.setBackground(Color.lightGray);

        addButton = new JButton("完成添加");
        //overallButton.addActionListener(new studentRank.overallListener());
        addButton.setBounds(810, 50, 90, 40);
        //overallButton.setFont(font);
        addButton.setBackground(Color.lightGray);




        setTitleType(numLabel);
        setTitleType(paperInfoLabel);
        setTitleType(paperDetailLabel);
        setTitleType(paperDeleteLabel);


        backButton = new JButton("返回");

        mainPanel.setLayout(null);

        backButton.setBackground(Color.lightGray);

        infoLabel.setBounds(80, 30, 200, 40);
        numLabel.setBounds(80, 120, 60, 50);
        paperInfoLabel.setBounds(140, 120, 600, 50);
        paperDetailLabel.setBounds(740, 120, 80, 50);
        paperDeleteLabel.setBounds(820, 120, 80, 50);

        backButton.setBounds(820, 560, 80, 30);
        backButton.addActionListener(new finishListener());

        mainPanel.add(paperDetailLabel);
        mainPanel.add(paperDeleteLabel);
        mainPanel.add(numLabel);
        mainPanel.add(infoLabel);
        mainPanel.add(paperInfoLabel);
        mainPanel.add(backButton);
        mainPanel.add(addButton);


        page = (size - 1) / 5 + 1;
        currentPage = 1;

        pageNumberLabel = new JLabel(currentPage + "/" + page);
        mainPanel.add(pageNumberLabel);
        // pageNumberLabel.setFont(pageNumberFont);
        pageNumberLabel.setBounds(430, 430, 80, 30);


        nextButton = new JButton("下一页");

        nextButton.setBounds(830, 510, 70, 30);
        nextButton.setFont(font);
        nextButton.setBackground(Color.lightGray);
        mainPanel.add(nextButton);




        //backButton.addActionListener(new studentRank.backListener());
        infoLabel.setHorizontalAlignment(SwingConstants.CENTER);
        infoLabel.setVerticalAlignment(SwingConstants.CENTER);
        this.setSize(980, 700);
        mainPanel.setSize(this.getSize());
        mainPanel.setBackground(Color.white);
        this.setBackground(Color.white);
        this.setContentPane(mainPanel);
        this.setLocationRelativeTo(null);//居中
        this.setTitle("学生在线考试平台");
        this.setVisible(true);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }
    public class finishListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            questionAddWindow.this.dispose();
            new organizePaperWindow(1);
        }
    }
    public class randomFinishListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            questionAddWindow.this.dispose();
            double max =organizePaperWindow.randomOrganize.max;
            double min =organizePaperWindow.randomOrganize.min;
            organizePaperWindow.randomOrganize=new organizePaperWindow(1.2);
            organizePaperWindow.randomOrganize.max=max;
            organizePaperWindow.randomOrganize.min=min;


        }
    }

}
